package com.yejiarong.weather.controller;

import com.yejiarong.common.tools.HttpResult;
import com.yejiarong.weather.bean.dto.WeatherRegionCodeDto;
import com.yejiarong.weather.service.IWeatherRegionService;
import org.springframework.web.bind.annotation.*;

/**
 * @author YeJR
 */
@RestController
@RequestMapping(value = "/weatherRegion")
public class WeatherRegionController {

    private final IWeatherRegionService weatherRegionService;

    public WeatherRegionController(IWeatherRegionService weatherRegionService) {
        this.weatherRegionService = weatherRegionService;
    }

    /**
     * 查询城市天气编码
     * @return HttpResult
     */
    @GetMapping(value = "/{province}")
    public HttpResult<String> getRegionCode(@PathVariable String province) {
        WeatherRegionCodeDto dto = new WeatherRegionCodeDto();
        dto.setProvince(province);
        return HttpResult.success(weatherRegionService.getRegionCode(dto));
    }

    /**
     * 查询城市天气编码
     * @return HttpResult
     */
    @GetMapping(value = "/{province}/{city}")
    public HttpResult<String> getRegionCode(@PathVariable String province, @PathVariable String city) {
        WeatherRegionCodeDto dto = new WeatherRegionCodeDto();
        dto.setProvince(province);
        dto.setCity(city);
        return HttpResult.success(weatherRegionService.getRegionCode(dto));
    }

    /**
     * 查询城市天气编码
     * @return HttpResult
     */
    @GetMapping(value = "/{province}/{city}/{county}")
    public HttpResult<String> getRegionCode(@PathVariable String province, @PathVariable String city, @PathVariable String county) {
        WeatherRegionCodeDto dto = new WeatherRegionCodeDto();
        dto.setProvince(province);
        dto.setCity(city);
        dto.setCounty(county);
        return HttpResult.success(weatherRegionService.getRegionCode(dto));
    }

}
